package chpt060403;

import java.util.Arrays;
import java.util.EmptyStackException;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item) throws FullStackExcpetion;
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 
}
class FullStackExcpetion extends Exception{

	public FullStackExcpetion() {
		super();
	}
}
class ArrayIntegerStack implements IntegerStack {
		
	private Integer[] arrStack;
	private int top=0;
	private int capacity;
	   
	public ArrayIntegerStack(int n){
		this.arrStack = new Integer[n];
}	
	@Override
	public Integer push(Integer item) throws FullStackExcpetion {
		if(item == null)
			return null;
		if(top == arrStack.length)
			throw new FullStackExcpetion();
		arrStack[top++]= item;
		return item;
	}

	@Override
	public Integer pop() throws EmptyStackException{
		
		if(top==0)
			throw new EmptyStackException();
		return arrStack[--top];
	}

	@Override
	public Integer peek() throws EmptyStackException{
		
		if(top==0)
			throw new EmptyStackException();
		return arrStack[top-1];
	}

	
	public boolean empty() {
		
		if(top == 0)
			return true;
		return false;
		
	}
	
	public int size() {
		
		return top;
	}
	public Integer[] getStack() {
		
		return arrStack;
	}
	
}
	



public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayIntegerStack Stack = new ArrayIntegerStack(n);
		int m = sc.nextInt();
		for (int i= 0; i< m ;i++) {
				Integer num = sc.nextInt();
				try {
					System.out.println(Stack.push(num));
				} catch (FullStackExcpetion e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		System.out.print(Stack.peek()+","+Stack.empty()+","+Stack.size()+"\n");
		System.out.println(Arrays.toString(Stack.getStack()));
		int x = sc.nextInt();
		for (int j= 0; j < x; j++) {
			System.out.println(Stack.pop());
		}
		System.out.print(Stack.peek()+","+Stack.empty()+","+Stack.size()+"\n");
		System.out.println(Arrays.toString(Stack.getStack()));
		
	}


}

